package ControleDiversas;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import JBCD.Conexao;
import ModeloAcademico.ModelCurso;
import ModeloAcademico.ModeloTurma;
import ModeloAcademico.ProfessoeBeen;
import ModeloAcademico.RegistroAulasBeen;


public class RegistroAulasDao {
	private RegistroAulasBeen registroaulas;
	private Connection conexao;

	public RegistroAulasDao() {
		registroaulas = new RegistroAulasBeen();
		conexao = new Conexao().getConnection();
	}
	
	// ------Inserindo dados na tabela-------------------------------------------------------------
	public void adicionaRegistroAulas(RegistroAulasBeen ra) throws SQLException {
		String sql = "INSERT INTO registroaulas (nomeprofessor,nometurma,nomecurso,data,conteudo) values (?,?,?,?,?)";

		PreparedStatement stmt = conexao.prepareStatement(sql);
		stmt.setString(1, ra.getProfessor());
		stmt.setString(2, ra.getTurma());
		stmt.setString(3, ra.getCurso());
		stmt.setString(4, ra.getData());
		stmt.setString(5, ra.getConteudo());
		stmt.execute();
		stmt.close();
	}

	
	// -------Pesquisando dados da tabela----------------------------------------------------------
	public List<RegistroAulasBeen> pesquisar() throws SQLException {
		List<RegistroAulasBeen> registroaulas = new ArrayList<RegistroAulasBeen>();

		String sql = "SELECT * FROM registroaulas";
		PreparedStatement stmt = conexao.prepareStatement(sql);

		ResultSet set = stmt.executeQuery();
		while (set.next()) {
			RegistroAulasBeen registro = new RegistroAulasBeen();
			registro.setProfessor(set.getString("nomeprofessor"));
			registro.setTurma(set.getString("nometurma"));
			registro.setCurso(set.getString("nomecurso"));
			registro.setData(set.getString("data"));
			registro.setConteudo(set.getString("conteudo"));
			registroaulas.add(registro);
		}
		return registroaulas;
	}
	

	// -------Pesquisando (nomes) da tabela professor--------------------------------------------

	public List<ProfessoeBeen> pesquisarProfessor() throws SQLException {
		List<ProfessoeBeen> professores = new ArrayList<ProfessoeBeen>();
		Vector<String> vet = new Vector<String>();
		String sql = "SELECT nome FROM professor ORDER BY nome";
		PreparedStatement stmt = conexao.prepareStatement(sql);
		ResultSet set = stmt.executeQuery();
		while (set.next()) {
			ProfessoeBeen listarProfessor = new ProfessoeBeen();
			vet.add(set.getString("nome").toString().trim());
			professores.add(listarProfessor);
		}
		return professores;
	}

	
	// --------Pesquisando (nomes) da tabela turma------------------------------------------------

	public List<ModeloTurma> pesquisarTurma() throws SQLException {
		List<ModeloTurma> turmas = new ArrayList<ModeloTurma>();

		String sql = "SELECT descricao FROM turma ORDER BY descricao";
		PreparedStatement stmt = conexao.prepareStatement(sql);
		ResultSet set = stmt.executeQuery();
		while (set.next()) {
			ModeloTurma listarTurma = new ModeloTurma();
			listarTurma.setNomeTurma(set.getString("descricao").toString()
					.trim());
			turmas.add(listarTurma);
		}
		return turmas;
	}

	
	// --------Pesquisando (nomes) da tabela curso-------------------------------------------------------------------------------------

	public List<ModelCurso> pesquisarCurso() throws SQLException {
		List<ModelCurso> cursos = new ArrayList<ModelCurso>();

		String sql = "SELECT nome FROM curso ORDER BY nome";
		PreparedStatement stmt = conexao.prepareStatement(sql);
		ResultSet set = stmt.executeQuery();
		while (set.next()) {
			ModelCurso listarCurso = new ModelCurso();    //criei construtor default
			listarCurso.setNome(set.getString("nome").toString().trim());
			cursos.add(listarCurso);
		}
		return cursos;
	}
}
